package ar.edu.utn.frba.disenio.gui;

import java.util.regex.Pattern;

import org.uqbar.arena.bindings.Transformer;
import org.uqbar.commons.model.UserException;

import ar.edu.utn.frba.disenio.fechas.Fecha;
import ar.edu.utn.frba.disenio.fechas.Formato;

public class FechaAdapter implements Transformer<Fecha,String> {

	@Override
	public Fecha viewToModel(String valueFromView) {
		if (! Pattern.matches("\\d\\d/\\d\\d/\\d\\d\\d\\d", valueFromView)){
			throw new UserException("El formato debe ser dd/MM/yyyy");
		} else {
			return new Fecha(new Formato("dd/MM/yyyy"),valueFromView);
		}
	}

	@Override
	public String modelToView(Fecha unaFecha) {
		return null;
	}

	@Override
	public Class<Fecha> getModelType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Class<String> getViewType() {
		// TODO Auto-generated method stub
		return null;
	}


}
